package xyz.xuminghai.javafx_learn.scene.effect;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.effect.ImageInput;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

import java.io.FileNotFoundException;
import java.net.URL;

/**
 * 2023/7/20 16:05 星期四<br/>
 * 一种源效果，它只是将给定的Image不加修改地作为另一个Effect输入传递
 *
 * @author xuMingHai
 */
public class ImageInputApp extends Application {

    private final BorderPane root = new BorderPane();

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void init() throws Exception {
        Rectangle rectangle = new Rectangle(400.0, 300.0);
        String fileName = "image-input-app.png";
        URL url = getClass().getResource(fileName);
        if (url == null) {
            throw new FileNotFoundException(fileName);
        }
        Image image = new Image(url.toExternalForm(), rectangle.getWidth(), rectangle.getHeight(), true, true);
        ImageInput imageInput = new ImageInput(image);
        rectangle.setEffect(imageInput);

        root.setCenter(rectangle);
    }


    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}
